import javax.microedition.lcdui.Graphics;

public final class ah extends ba
    implements br
{

    private ba c;
    public int a;
    public int b;
    private int d;
    private ar e;
    private ar f;
    private int g;
    private int h;

    public ah(o o1, ba ba1)
    {
        this(o1, ba1, -100, -100);
    }

    public ah(o o1, ba ba1, int j, int k)
    {
        super(o1, j, k);
        d = 50;
        e = new ar(300);
        f = new ar(300);
        g = 0;
        h = 0;
        a(0, ba1);
    }

    public final void b(int j)
    {
        if(j <= 0)
            j = 1;
        d = j;
    }

    public final boolean a(int ai[])
    {
        ai[0] = e();
        ai[1] = h_();
        ai[2] = a;
        ai[3] = f();
        ai[4] = d();
        ai[5] = b;
        return true;
    }

    public final int h_()
    {
        return x() - super.I.g();
    }

    public final int d()
    {
        return y() - super.I.h();
    }

    public final int e()
    {
        return e.a;
    }

    public final int f()
    {
        return f.a;
    }

    public final int h()
    {
        return e.d;
    }

    public final int i()
    {
        return f.d;
    }

    public final boolean a(bk bk1)
    {
        int j = e.d;
        int k = f.d;
        int l = h_();
        int i1 = d();
        return bk1.a(j, k, l, i1);
    }

    public final boolean c(int j)
    {
        int k = d();
        if(j + k > b)
            j = b - k;
        if(j < 0)
            j = 0;
        if(f.d != j)
        {
            f.c(j);
            bh.b().a(this, -8);
            bh.b().b((br)this);
            return true;
        } else
        {
            return false;
        }
    }

    public final boolean d(int j)
    {
        int k = h_();
        if(j + k > a)
            j = a - k;
        if(j < 0)
            j = 0;
        if(e.d != j)
        {
            e.c(j);
            bh.b().a(this, -8);
            bh.b().b((br)this);
            return true;
        } else
        {
            return false;
        }
    }

    public final boolean a(int j, int k, int l, int i1, int j1)
    {
        boolean flag = j == 1 || j == 6;
        boolean flag1 = a(true, flag, j1, l);
        boolean flag2 = a(false, !flag, k, i1);
        return flag1 || flag2;
    }

    private boolean a(boolean flag, boolean flag1, int j, int k)
    {
        int l = flag ? h_() : d();
        int i1 = !flag1 && k - j < l ? l / 4 : 0;
        int j1;
        int k1 = (j1 = (flag ? e : f).a) + l;
        int l1 = 0;
        if(k - j - i1 > l)
        {
            if(j1 <= j && j < k1)
                return false;
            if(j1 <= k && k < k1)
                return false;
            if(k < j1)
                l1 = k - l;
            else
            if(j >= k1)
                l1 = j;
            else
                return false;
        } else
        if(j - i1 < j1)
            l1 = j - i1;
        else
        if(k + i1 >= k1)
            l1 = (k - l) + i1;
        else
            return false;
        if(flag)
            return d(l1);
        else
            return c(l1);
    }

    public final int g_()
    {
        return 1;
    }

    public final ba a(int j)
    {
        return c;
    }

    public final void a(int j, ba ba1)
    {
        if(ba1 != null)
        {
            ba1.H = this;
            if(ba1.O == -100)
                ba1.O = 0;
        }
        c = ba1;
    }

    public final int g()
    {
        if(c != null)
            return c.u();
        else
            return 0;
    }

    public final int g(int j)
    {
        if(c != null)
            return c.j(j);
        else
            return 0;
    }

    public final int a(int j, int k, int l, int i1)
    {
        ba ba1;
        if((ba1 = c) != null)
        {
            if(ba1 instanceof ap)
            {
                int j1 = l;
                int l1 = i1;
                if(ba1.v())
                    j1 = bh.b(ba1.u(), l);
                if(ba1.w())
                    l1 = bh.b(ba1.j(0), i1);
                ba1.b(0, 0, j1, l1);
                a = ba1.K.f;
                b = ba1.K.g;
            } else
            {
                a = bh.b(ba1.u(), l);
                b = bh.b(ba1.j(a), i1);
                ba1.b(0, 0, a, b);
            }
            int k1;
            if((k1 = e.d) + l > a)
                k1 = a - l;
            if(k1 < 0)
                k1 = 0;
            int i2;
            if((i2 = f.d) + i1 > b)
                i2 = b - i1;
            if(i2 < 0)
                i2 = 0;
            e.a(k1);
            f.a(i2);
        }
        return b;
    }

    public final void a(Graphics g1, bh bh1, o o1, int j, int k)
    {
        g1.translate(-e.a, -f.a);
        if(c != null)
            bh.a(g1, bh1, c);
        g1.translate(e.a, f.a);
    }

    public final boolean e(int j)
    {
        int k;
        switch(j)
        {
        case 3: // '\003'
        case 4: // '\004'
        default:
            break;

        case 1: // '\001'
            if((k = f.d) > 0)
                return c(k - (d() * d) / 100);
            else
                return false;

        case 6: // '\006'
            k = f.d;
            int i1 = d();
            if(k + i1 < b)
                return c(k + (i1 * d) / 100);
            break;

        case 2: // '\002'
            if((k = e.d) > 0)
                return d(k - (h_() * d) / 100);
            else
                return false;

        case 5: // '\005'
            int l = e.d;
            int j1 = h_();
            if(l + j1 < a)
                return d(l + (j1 * d) / 100);
            break;
        }
        return false;
    }

    public final int b_(int j)
    {
        A();
        boolean flag = e.b(2, j);
        boolean flag1 = f.b(2, j);
        return !flag && !flag1 ? 0 : 40;
    }

    public final boolean a(int j, int k, int l)
    {
        if(j == 3)
        {
            int i1 = g - k;
            int j1 = h - l;
            d(e.c + i1);
            c(f.c + j1);
            return true;
        }
        if(j == 1)
        {
            g = k;
            h = l;
        }
        return c.a(j, (k - super.K.d - super.I.c()) + e.a, (l - super.K.e - super.I.e()) + f.a);
    }
}